package nccloud.web.arap.mullevelpay.mullevelpayvo.action;

import nccloud.framework.core.exception.ExceptionUtils;
import nccloud.framework.core.io.WebFile;
import nccloud.framework.core.json.IJson;
import nccloud.framework.web.action.itf.ICommonAction;
import nccloud.framework.web.container.IRequest;
import nccloud.framework.web.convert.translate.Translator;
import nccloud.framework.web.json.JsonFactory;
import nccloud.framework.web.ui.pattern.extbillcard.ExtBillCard;
import nccloud.framework.web.ui.pattern.grid.Grid;
import nccloud.web.arap.util.mullevelpay.MullevelpayMainUtil;

public class ImportAction implements ICommonAction
{
	  public Object doAction(IRequest request)
	  {
	    WebFile[] webfiles = request.readFiles();
	    Grid grid = null;
	    IJson json = JsonFactory.create();
	    String read = ((String[])request.readParameters().get("data"))[0];
	    ExtBillCard extbillcard = (ExtBillCard)json.fromJson(read, ExtBillCard.class);
	    try
	    {
	      grid = MullevelpayMainUtil.getGrid(webfiles[0].getInputStream(), extbillcard);
	      grid.setTempletid(extbillcard.getTempletid());
	      grid.setPageid(extbillcard.getPageid());
	      Translator translator = new Translator();
	      translator.translate(grid);
	      extbillcard.addBody(grid);

	      return extbillcard;
	    } catch (Exception e) {
	      ExceptionUtils.wrapException(e);
	    }
	    return null;
	  }
	}